﻿@{
    ViewData["Title"] = "Admin";
}
<h2>
    欢迎用户：@ViewData["Userno"]
</h2>

<h3>测试试卷：@ViewBag.Papers.Tables[0].Rows[0][1]</h3>
<div class="table-responsive">
    <table class="table table-hover">
        <thead>
            <tr>
                <th>题目</th>
                <th>题目名称</th>
                <th>@ViewBag.Papers.Tables[0].Rows[0][4]</th>
                <th>@ViewBag.Papers.Tables[0].Rows[0][5]</th>
                <th>@ViewBag.Papers.Tables[0].Rows[0][6]</th>
                <th>@ViewBag.Papers.Tables[0].Rows[0][7]</th>

            </tr>
        </thead>
        <tbody>
            @{ int i = 0; }
            @foreach (var Row in ViewBag.Paperitem.Tables[0].Rows)
            {
                i++;
                <tr>
                    <th>@i</th>
                    <th>@Row[1]</th>
                    <th>
                        <label class="radio-inline">
                            <input type="radio" name="Radio_@i" value="@Row[3]"> 选项 1
                        </label>
                    </th>
                    <th>
                        <label class="radio-inline">
                            <input type="radio" name="Radio_@i" value="@Row[4]"> 选项 2
                        </label>
                    </th>
                    <th>
                        <label class="radio-inline">
                            <input type="radio" name="Radio_@i" value="@Row[5]"> 选项 3
                        </label>
                    </th>
                    <th>
                        <label class="radio-inline">
                            <input type="radio" name="Radio_@i" value="@Row[6]"> 选项 4
                        </label>
                    </th>
                </tr>
            }
        </tbody>
    </table>
</div>
<button id="test" type="button" class="btn btn-primary">提交测试</button>
<button type="button" class="btn btn-default" onclick="window.location.href = '/Student/Index'">返回</button>

<script>
    $(document).ready(function () {
        var id = "@ViewData["Userno"]"
        if (id == "") {
            window.location.href = '/';
        };
    })
    var gradeproduct = @ViewBag.Papers.Tables[0].Rows[0][3];
    var Datas = {
    create: function () {
    papers: "";
    grade: "";
    return Datas;
    }
    }
    $("#test").click(function () {
        var vals = 0;
        $("input:checked").each(function () {
            vals += Number($(this).val())
        });
        var score = vals * gradeproduct
        var newDatas = Datas.create();
        newDatas.papers = @ViewBag.Papers.Tables[0].Rows[0][0];
        newDatas.grade = score;
        $.ajax({
            url: "/Student/AddGrade",
            type: "POST",
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(newDatas),
        success: function () {
            alert("你的测试分数为：" + score)
            window.location.href = '/Student/Index'
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert("请求失败，消息：" + textStatus + "  " + errorThrown);
        }
    });
    })
</script>
